package com.jrx.anytxn.reporting.service.impl;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.common.uitl.DateUtils;
import com.jrx.anytxn.customer.dto.bankcardinfo.BankCardRes;
import com.jrx.anytxn.customer.service.IBankCardService;
import com.jrx.anytxn.number.exception.SegmentException;
import com.jrx.anytxn.number.service.ISegmentService;
import com.jrx.anytxn.param.constant.ErrorMsgConstant;
import com.jrx.anytxn.param.entity.BtBatchStatus;
import com.jrx.anytxn.param.entity.PrOrganizationTable;
import com.jrx.anytxn.param.entity.PrPenaltyRateTable;
import com.jrx.anytxn.param.entity.PrProductTable;
import com.jrx.anytxn.param.mapper.ext.ExtBtBatchStatusMapper;
import com.jrx.anytxn.param.mapper.ext.ExtPrPenaltyRateTableMapper;
import com.jrx.anytxn.param.mapper.ext.ExtPrProductTableMapper;
import com.jrx.anytxn.param.service.system.IOrganizationTableService;
import com.jrx.anytxn.reporting.bean.ReportingDataBean;
import com.jrx.anytxn.reporting.constant.ReportingConstant;
import com.jrx.anytxn.reporting.entity.MrLoanAccountInfo;
import com.jrx.anytxn.reporting.entity.MrRepaymentPlan;
import com.jrx.anytxn.reporting.mapper.base.MrLoanAccountInfoMapper;
import com.jrx.anytxn.reporting.mapper.base.MrRepaymentPlanMapper;
import com.jrx.anytxn.reporting.mapper.ext.ExtMrLoanAccountInfoMapper;
import com.jrx.anytxn.reporting.mapper.ext.ExtMrRepaymentPlanMapper;
import com.jrx.anytxn.reporting.service.IReportingDataDealService;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.*;
import com.jrx.anytxn.transaction.mapper.ext.*;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
public class ReportingDataDealServiceImpl implements IReportingDataDealService {

    Logger logger = LoggerFactory.getLogger(ReportingDataDealServiceImpl.class);

    @Autowired
    private ISegmentService segmentService;
    @Resource
    private ExtPrProductTableMapper extPrProductTableMapper;
    @Resource
    private MrLoanAccountInfoMapper mrLoanAccountInfoMapper;
    @Autowired
    private IBankCardService bankCardService;
    @Resource
    private ExtPrPenaltyRateTableMapper extPrPenaltyRateTableMapper;
    @Resource
    private ExtAmDelinquencyInfoMapper extAmDelinquencyInfoMapper;
    @Resource
    private ExtAmRepaymentPlanInfoMapper extAmRepaymentPlanInfoMapper;
    @Resource
    private ExtMrRepaymentPlanMapper extMrRepaymentPlanMapper;
    @Resource
    private ExtMrLoanAccountInfoMapper extMrLoanAccountInfoMapper;
    @Resource
    private MrRepaymentPlanMapper mrRepaymentPlanMapper;
    @Resource
    private ExtAmInterestAccrualInfoMapper extAmInterestAccrualInfoMapper;
    @Autowired
    private IOrganizationTableService organizationTableService;
    @Resource
    private ExtBtBatchStatusMapper extBtBatchStatusMapper;
    @Resource
    private ExtAmAccountMainInfoMapper extAmAccountMainInfoMapper;
    @Resource
    private ExtAmLoanMainInfoMapper extAmLoanMainInfoMapper;
    @Resource
    private ExtTlDisbursementLogMapper extTlDisbursementLogMapper;


    @Override
    public ReportingDataBean assemReportingData(AmLoanAccountInfo accountInfo) throws TxnBizException{
        TlDisbursementLog tlDisbursementLog = extTlDisbursementLogMapper.selectByLoanIdAndSumStatuss(accountInfo.getLoanId(),accountInfo.getCustomerId(),accountInfo.getTenantId(),
                Arrays.asList(ReportingConstant.DISBURSEMENT_LOG_SUM_STATUS_F,ReportingConstant.DISBURSEMENT_LOG_SUM_STATUS_S));

        PrOrganizationTable org = organizationTableService.findByOrgIdForBatch(ReportingConstant.DEFAULT_ORG_NUMBER);

        if(null == tlDisbursementLog || tlDisbursementLog.getCollateDate().compareTo(org.getToday()) > 0){
            return null;
        }

        ReportingDataBean reportingDataBean = new ReportingDataBean();
        logger.info("amLoanAccountInfo 参数信息 :" + accountInfo.toString());

        AmLoanMainInfo amLoanMainInfo = extAmLoanMainInfoMapper.selectByLoanId(
                accountInfo.getLoanId(),accountInfo.getCustomerId(),
                accountInfo.getTenantId(),accountInfo.getChannel());

        MrLoanAccountInfo mrLoanAccountInfo = BeanMapping.copy(amLoanMainInfo, MrLoanAccountInfo.class);

        //判断新增还是修改
        MrLoanAccountInfo oldMrLoanAccountInfo = extMrLoanAccountInfoMapper.selectLoanByCusIdAndLoanId(amLoanMainInfo.getChannel(),amLoanMainInfo.getCustomerId(),
                amLoanMainInfo.getLoanId(),amLoanMainInfo.getTenantId());


        mrLoanAccountInfo.setBusinessDate(org.getNextProcessingDate());
        //新增订单
        if(null == oldMrLoanAccountInfo){
            reportingDataBean.setFlag(0);//新增
            try {
                mrLoanAccountInfo.setId(segmentService.getId(ReportingConstant.MR_LOAN_ACCOUNT_ID));
            } catch (SegmentException e) {
                logger.error("主键生成错误", e);
                throw new TxnBizException(ErrorMsgConstant.ERROR_ID);
            }
            mrLoanAccountInfo.setAmortMethod(amLoanMainInfo.getAmortMethodTableId());//还款方式

            mrLoanAccountInfo.setPayedTenor(accountInfo.getPayedTenor());
            mrLoanAccountInfo.setBusinessType(ReportingConstant.BUSINESS_TYPE_LOAN);//业务种类
            mrLoanAccountInfo.setOccurPlace("120000");//租户的区域码
            PrProductTable prProductTable = extPrProductTableMapper.selectByProductIdAndOrgIdAndStatus(amLoanMainInfo.getProductId(),
                    amLoanMainInfo.getOrganizationId(),null,amLoanMainInfo.getTenantId());
            mrLoanAccountInfo.setDog(prProductTable.getGraceDays());//宽限天数
            mrLoanAccountInfo.setPayMode(prProductTable.getRepaymentType());//还款类型 1-自主支付 2-受托支付
            mrLoanAccountInfo.setRtnDateType(prProductTable.getPaymentDateType());//还款日确定方式
            mrLoanAccountInfo.setLoanDurationUnit(prProductTable.getLoanDurationUnit());
            mrLoanAccountInfo.setShareContractAmount(amLoanMainInfo.getLoanAmount());
            mrLoanAccountInfo.setApplyDate(amLoanMainInfo.getPostingDate());
            mrLoanAccountInfo.setReleaseDate(amLoanMainInfo.getCreateTime());
            mrLoanAccountInfo.setAssureType(ReportingConstant.ASSURE_TYPE_00);//信用
            //五级分类
            mrLoanAccountInfo.setLoanClassify(accountInfo.getLoanClassify());
            mrLoanAccountInfo.setNature(ReportingConstant.CONTRACT_NATURE_1);//一般担保合同
            mrLoanAccountInfo.setAccountStatus(accountInfo.getAccountStatus());
            mrLoanAccountInfo.setOvdDays(accountInfo.getDelqDays());
            mrLoanAccountInfo.setAppstat(ReportingConstant.LOAN_APPROVAL_STATUS_6);//担保类型
            //查询客户卡片信息
            List<BankCardRes> cardList = bankCardService.getBankCardList(amLoanMainInfo.getCustomerId(),amLoanMainInfo.getChannel(),"1",amLoanMainInfo.getTenantId());
            for(BankCardRes res : cardList){
                if(res.getDefaultPaymentCard().equals("Y")){
                    mrLoanAccountInfo.setRtnCardno(res.getCardNumber());
                }
                if(res.getDefaultLoanCard().equals("Y")){
                    mrLoanAccountInfo.setPayCardno(res.getCardNumber());
                }
            }
            mrLoanAccountInfo.setPayMode(ReportingConstant.PAY_MODE_1);
            mrLoanAccountInfo.setIntrate(amLoanMainInfo.getActualDailyRate());
            //罚息参数
            PrPenaltyRateTable prPenaltyRateTable = extPrPenaltyRateTableMapper.selectByPenaltyId(amLoanMainInfo.getPenaltyTableId(),amLoanMainInfo.getOrganizationId(),amLoanMainInfo.getTenantId());
            mrLoanAccountInfo.setPfltintrateOpt(prPenaltyRateTable.getIncreaseType());
            mrLoanAccountInfo.setPfltintrate(prPenaltyRateTable.getIncreaseNum());
            if(mrLoanAccountInfo.getPfltintrateOpt().equals(ReportingConstant.PFLTUBTRATE_OPT_1)){
                BigDecimal percent = prPenaltyRateTable.getIncreaseNum().add(BigDecimal.ONE);
                BigDecimal pintrate = amLoanMainInfo.getActualDailyRate().multiply(percent);
                mrLoanAccountInfo.setPintrate(pintrate);
            }else{
                BigDecimal pintrate = amLoanMainInfo.getActualDailyRate().add(prPenaltyRateTable.getIncreaseNum());
                mrLoanAccountInfo.setPintrate(pintrate);
            }
            if(prPenaltyRateTable.getAccrualBasic().equals(ReportingConstant.ACCRUAL_BASIC_1)){
                mrLoanAccountInfo.setIscomint(ReportingConstant.COMPOUND_INTEREST_1);
            }else{
                mrLoanAccountInfo.setIscomint(ReportingConstant.COMPOUND_INTEREST_0);
            }
            mrLoanAccountInfo.setPayDirect(ReportingConstant.PAY_DIRECT_2);//支付方式
            mrLoanAccountInfo.setCloseType(ReportingConstant.CLOSE_TYPE_0);//结清标志
            mrLoanAccountInfo.setDogType(ReportingConstant.DOG_TYPE_1);//宽限类型
            mrLoanAccountInfo.setIsdogflag(prPenaltyRateTable.getValueDate());//宽限期是否计息 0 否 1是
            mrLoanAccountInfo.setLoanUse(amLoanMainInfo.getLoanUse());
            mrLoanAccountInfo.setGrantMode("0");//一次性发放
            mrLoanAccountInfo.setCurrency("CNY");//人民币
            mrLoanAccountInfo.setLoanAmount(amLoanMainInfo.getLoanAmount());//合同金额
            mrLoanAccountInfo.setInputDate(amLoanMainInfo.getCreateTime());
            mrLoanAccountInfo.setMaxOvdPeri(0);

        }else {
            //更新
            reportingDataBean.setFlag(1);//更新
            mrLoanAccountInfo.setPayedTenor(accountInfo.getPayedTenor());//已还期数
            if(mrLoanAccountInfo.getOverdueDate() == null){
                //获取延滞交易账户
                AmDelinquencyInfo amDelinquencyInfo = extAmDelinquencyInfoMapper.getMinAmDelinquencyInfo(amLoanMainInfo.getLoanId(),amLoanMainInfo.getCustomerId(),amLoanMainInfo.getTenantId());
                if(null != amDelinquencyInfo){
                    mrLoanAccountInfo.setOverdueDate(amDelinquencyInfo.getDelqDate());//最早逾期日期
                }
            }
            mrLoanAccountInfo.setMaxOvdPeri(Integer.max(oldMrLoanAccountInfo.getMaxOvdPeri(),accountInfo.getContinueOverDueTenor()));
            PrProductTable prProductTable = extPrProductTableMapper.selectByProductIdAndOrgIdAndStatus(amLoanMainInfo.getProductId(),
                    amLoanMainInfo.getOrganizationId(),null,amLoanMainInfo.getTenantId());
            mrLoanAccountInfo.setDog(prProductTable.getGraceDays());//宽限天数
            mrLoanAccountInfo.setAccountStatus(accountInfo.getAccountStatus());//账户状态
            mrLoanAccountInfo.setOvdDays(accountInfo.getDelqDays());//当前逾期天数
            mrLoanAccountInfo.setLoanClassify(accountInfo.getLoanClassify());//五级分类
            mrLoanAccountInfo.setTotOvdTimes(accountInfo.getTotalCompensatoryTenor());//总逾期次数
            //查询还款计划 获取当前逾期期次
            AmRepaymentPlanInfo planInfo = extAmRepaymentPlanInfoMapper.selectMaxOverPlan(amLoanMainInfo.getLoanId(),amLoanMainInfo.getCustomerId(),amLoanMainInfo.getTenantId());
            if(null != planInfo){
                mrLoanAccountInfo.setOvdPeri(planInfo.getBillingTenor());//当前逾期期数
            }else{
                mrLoanAccountInfo.setOvdPeri(0);//当前逾期期数
            }
        }

        if(Arrays.asList(TransBizConstant.LOAN_STATUS_7,TransBizConstant.LOAN_STATUS_8).contains(accountInfo.getAccountStatus())){
            mrLoanAccountInfo.setPayoffDate(accountInfo.getPayoffDate());
            mrLoanAccountInfo.setCloseType(ReportingConstant.CLOSE_TYPE_1);//结清标志
        }
        
        mrLoanAccountInfo.setCurrBalance(accountInfo.getCurrBalance());//余额
        mrLoanAccountInfo.setPrincipalBalance(accountInfo.getPrincipalBalance());//本金余额
        mrLoanAccountInfo.setInterestBalance(accountInfo.getInterestBalance());//利息余额
        mrLoanAccountInfo.setPrincipalBalance(accountInfo.getPenaltyBalance());//罚息余额
        mrLoanAccountInfo.setCompoundBalance(accountInfo.getCompoundBalance());//复利余额
        mrLoanAccountInfo.setFeeBalance(accountInfo.getFeeBalance());//费用余额
        mrLoanAccountInfo.setRemainPrincipal(accountInfo.getRemainPrincipal());//剩余本金
        mrLoanAccountInfo.setAccruedInterest(accountInfo.getAccruedInterest());//计提利息
        mrLoanAccountInfo.setAccruedPenalty(accountInfo.getAccruedPenalty());//计提罚息
        mrLoanAccountInfo.setAccruedCompound(accountInfo.getAccruedCompound());//计提复利
        mrLoanAccountInfo.setChargeoffFlag(accountInfo.getChargeoffFlag());//核销标志
        mrLoanAccountInfo.setChargeoffAmount(accountInfo.getChargeoffAmount());//核销金额
        mrLoanAccountInfo.setChargeoffDate(accountInfo.getChargeoffDate());//核销日期

        reportingDataBean.setMrLoanAccountInfo(mrLoanAccountInfo);

        //组装还款计划 按照时间获取对应还款计划
        logger.info( "组装还款计划信息");
        createMrRepaymentPlan(accountInfo,reportingDataBean,org);


        return reportingDataBean;
    }

    @Override
    public void saveReportingDate(ReportingDataBean reportingDataBean) {
        if (reportingDataBean.getFlag() == 0 ) {
            mrLoanAccountInfoMapper.insertSelective(reportingDataBean.getMrLoanAccountInfo());
            List<MrRepaymentPlan> list = reportingDataBean.getInsertMrRepaymentPlanList();
            for(MrRepaymentPlan plan : list){
                mrRepaymentPlanMapper.insertSelective(plan);
            }
        } else {
            extMrLoanAccountInfoMapper.updateByLoanIdSelective(reportingDataBean.getMrLoanAccountInfo());
            if(CollectionUtils.isNotEmpty(reportingDataBean.getUpdateMrRepaymentPlanList())){
                extMrRepaymentPlanMapper.batchUpdateMrRepaymentPlan(reportingDataBean.getUpdateMrRepaymentPlanList());
            }
            //提前部分还款 需要生成新的还款计划
            if(CollectionUtils.isNotEmpty(reportingDataBean.getInsertMrRepaymentPlanList())){
                List<MrRepaymentPlan> list = reportingDataBean.getInsertMrRepaymentPlanList();
                for(MrRepaymentPlan plan : list){
                    mrRepaymentPlanMapper.insertSelective(plan);
                }
            }
        }
    }

    private void createMrRepaymentPlan(AmLoanAccountInfo amLoanAccountInfo,ReportingDataBean reportingDataBean, PrOrganizationTable org) throws TxnBizException {
        List<MrRepaymentPlan> updatePlanList = new ArrayList<>();
        List<MrRepaymentPlan> insertPlanList = new ArrayList<>();

        BtBatchStatus btBatchStatus = extBtBatchStatusMapper.selectByStatusAndJobName(
                ReportingConstant.BATCH_SATTUS_2,ReportingConstant.CUTOVER_END,org.getTenantId(),
                org.getToday());
        String startTime = null;
        if(null != btBatchStatus){
            startTime = DateUtils.format(btBatchStatus.getCreateTime(),"yyyy-MM-dd HH:mm:ss");
        }
        List<AmRepaymentPlanInfo> planInfos = extAmRepaymentPlanInfoMapper.selectRepaymentPlanInfoListByUpdateTimeAndLoanId(amLoanAccountInfo.getLoanId(),amLoanAccountInfo.getCustomerId(),
                amLoanAccountInfo.getTenantId(),startTime);
        for(AmRepaymentPlanInfo planInfo : planInfos){
            //判断是新增还是修改
            int countNumber = extMrRepaymentPlanMapper.countRepaumenPlan(planInfo.getId());

            MrRepaymentPlan plan = BeanMapping.copy(planInfo, MrRepaymentPlan.class);
            plan.setBusinessDate(org.getNextProcessingDate());
            if(0 == countNumber){
                plan.setId(planInfo.getId());
                plan.setPaydate(planInfo.getPaymentDueDate());//还款日
                plan.setActualpaydate(planInfo.getTransactionDate());
                plan.setCompoundInterest(BigDecimal.ZERO);
                plan.setPenaltyInterest(BigDecimal.ZERO);
                Date periodpaydate = DateUtils.getDate(planInfo.getPaymentDueDate(),reportingDataBean.getMrLoanAccountInfo().getDog());//宽限期最后一天
                plan.setPeriodpaydate(periodpaydate);//宽限期最后一天
                plan.setInputDate(planInfo.getCreateTime());//导入时间
                if(ReportingConstant.LOAN_PLAN_STATUS_7.equals(planInfo.getPlanStatus()) || ReportingConstant.LOAN_PLAN_STATUS_8.equals(planInfo.getPlanStatus())){
                    plan.setPayOffStatus("1");
                }else{
                    plan.setPayOffStatus("0");
                }
                insertPlanList.add(plan);
            }else{
                //更新
                plan.setPlanStatus(planInfo.getPlanStatus());
                plan.setPaydate(planInfo.getPaymentDueDate());//还款日
                plan.setActualpaydate(planInfo.getTransactionDate());
                plan.setInputDate(planInfo.getCreateTime());//导入时间
                //应还总金额
                BigDecimal total_amount = planInfo.getTotalAmount();
                if(ReportingConstant.LOAN_PLAN_STATUS_7.equals(planInfo.getPlanStatus()) || ReportingConstant.LOAN_PLAN_STATUS_8.equals(planInfo.getPlanStatus())){
                    plan.setPayOffStatus("1");
                    plan.setPenaltyInterest(planInfo.getRepayPenaltyInterest());
                    plan.setCompoundInterest(planInfo.getRepayCompoundInterest());
                    total_amount = total_amount.add(planInfo.getRepayPenaltyInterest()).add(planInfo.getRepayCompoundInterest());
                    plan.setTotalAmount(total_amount);
                    plan.setOverPrincipal(BigDecimal.ZERO);
                    plan.setOverInterest(BigDecimal.ZERO);
                }else if(ReportingConstant.LOAN_PLAN_STATUS_2.equals(planInfo.getPlanStatus())) {
                    //获取还款计划罚息，复利累计  部分还款还需计算罚息 复利交易账户
                    BigDecimal totalPentIntr = BigDecimal.ZERO;//总罚息（累计 + 已还）
                    //计算罚息累计账户中的罚息金额
                    List<AmInterestAccrualInfo> accruPentAcctList = extAmInterestAccrualInfoMapper.selectAccuAcct(
                            planInfo.getLoanId(), planInfo.getCustomerId(), planInfo.getTenantId(), ReportingConstant.INTEREST_ACCRUAL_TYPE_10, planInfo.getBillingTenor(), ReportingConstant.ACCOUNT_STATUS_1);
                    if (CollectionUtils.isNotEmpty(accruPentAcctList)) {
                        totalPentIntr = totalPentIntr.add(accruPentAcctList.stream().map(AmInterestAccrualInfo::getAccrualTotalAccruInterest).reduce(BigDecimal.ZERO,BigDecimal::add));
                    }
                    //计算已还罚息
                    List<AmAccountMainInfo> penInfoList = extAmAccountMainInfoMapper.selectAccount(planInfo.getLoanId(), planInfo.getCustomerId(),
                            planInfo.getTenantId(),Arrays.asList(ReportingConstant.ACCOUNT_TYPE_11),
                            planInfo.getBillingTenor(),
                            Arrays.asList(ReportingConstant.ACCOUNT_STATUS_1, ReportingConstant.ACCOUNT_STATUS_2,
                                    ReportingConstant.ACCOUNT_STATUS_6,ReportingConstant.ACCOUNT_STATUS_7,ReportingConstant.ACCOUNT_STATUS_8));
                    if(CollectionUtils.isNotEmpty(penInfoList)){
                        for(AmAccountMainInfo amAccountMainInfo : penInfoList){
                            totalPentIntr = totalPentIntr.add(amAccountMainInfo.getPostingAmount());
                        }
                    }
                    plan.setPenaltyInterest(totalPentIntr);//应还罚息 累计+已还

                    //获取罚息复利
                    BigDecimal totalCompountIntr = BigDecimal.ZERO;//复利
                    //计算罚息累计账户中的罚息金额
                    List<AmInterestAccrualInfo> accruCompAcctList = extAmInterestAccrualInfoMapper.selectAccuAcct(
                            planInfo.getLoanId(), planInfo.getCustomerId(), planInfo.getTenantId(), ReportingConstant.INTEREST_ACCRUAL_TYPE_20, planInfo.getBillingTenor(), ReportingConstant.ACCOUNT_STATUS_1);
                    if (CollectionUtils.isNotEmpty(accruCompAcctList)) {
                        totalCompountIntr = totalCompountIntr.add(accruCompAcctList.stream().map(AmInterestAccrualInfo::getAccrualTotalAccruInterest).reduce(BigDecimal.ZERO,BigDecimal::add));
                    }
                    //已还复利
                    List<AmAccountMainInfo> compInfoList = extAmAccountMainInfoMapper.selectAccount(planInfo.getLoanId(), planInfo.getCustomerId(),
                            planInfo.getTenantId(),Arrays.asList(ReportingConstant.ACCOUNT_TYPE_12),
                            planInfo.getBillingTenor(),
                            Arrays.asList(ReportingConstant.ACCOUNT_STATUS_1, ReportingConstant.ACCOUNT_STATUS_2,
                                    ReportingConstant.ACCOUNT_STATUS_6,ReportingConstant.ACCOUNT_STATUS_7,ReportingConstant.ACCOUNT_STATUS_8));
                    if(CollectionUtils.isNotEmpty(compInfoList)){
                        for(AmAccountMainInfo compInfo : compInfoList){
                            totalCompountIntr = totalCompountIntr.add(compInfo.getPostingAmount());
                        }
                    }
                    plan.setCompoundInterest(totalCompountIntr);//应还罚息 累计+已还
                    //总欠款
                    total_amount = total_amount.add(plan.getPenaltyInterest()).add(plan.getCompoundInterest());

                    plan.setTotalAmount(total_amount);

                    plan.setOverPrincipal(planInfo.getPrincipalAmount());//逾期本金
                    plan.setOverInterest(planInfo.getInterestAmount());//逾期利息
                } else{
                    plan.setPenaltyInterest(BigDecimal.ZERO);
                    plan.setCompoundInterest(BigDecimal.ZERO);
                    plan.setOverPrincipal(BigDecimal.ZERO);
                    plan.setOverInterest(BigDecimal.ZERO);
                }
                updatePlanList.add(plan);
            }
        }
        reportingDataBean.setInsertMrRepaymentPlanList(insertPlanList);
        reportingDataBean.setUpdateMrRepaymentPlanList(updatePlanList);

    }
}
